<meta name="csrf-token" content="{{ csrf_token() }}">
<style>
    .box-solid {
        margin-top: 20px;
    }
</style>
<a href="cascades/create"><button class="btn btn-primary">添加学科</button></a>
<button onClick="del();" class="btn btn-danger">删除学科</button>
<form action="" id="form">
@forelse ($list as $li)
<div class="box box-solid">
    <div class="box-header with-border">
        <i class="fa fa-text-width"></i>
        <h3 class="box-title">{{$li->name}}</h3>
    </div>
    <div class="box-body">

            <div>
                <label for="name" style="margin-right: 30px;">年级</label>
                @isset($li->grade)
                @forelse ($li->grade as $grade)
                <label class="checkbox-inline">
                    <input type="checkbox" value="{{$grade->id}}">{{$grade->name}}
                </label>
                @empty
                @endforelse
                @endisset
            </div>
            <div>
                <label for="name" style="margin-right: 30px;">学科</label>
                @isset($li->subject)
                @forelse ($li->subject as $subject)
                <label class="checkbox-inline">
                    <input type="checkbox" value="{{$subject->id}}">{{$subject->name}}
                </label>
                @empty
                @endforelse
                @endisset
            </div>
    </div>
</div>
@empty

@endforelse
</form>

<script>
    
    // 事件
    // $(document).pjax('#del', '#pjax-container')
    //方法
    function del(){
        //获取选中的ids
        var ids = [];
        $("input[type=checkbox]:checked").each(function(){
            ids.push($(this).val());
        });
        //数组转字符串
        ids = ids.join(',');
        var url = 'cascades_del/'+ids;
        $.pjax({url: url, container: '#pjax-container',type:'get'});
    }
</script>